package cn.honglian.config;

import cn.honglian.fliter.RequestTimeFilter;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @BelongsProject: springcloudnetflix-parent
 * @BelongsPackage: cn.itsource.config
 * @Author: Director
 * @CreateTime: 2022-07-29  18:08
 * @Description: 自定义过滤器的配置类
 * @Version: 1.0
 */
@Configuration // 标识当前类是一个配置类
public class FilterConfig {

    // 配置Filter作用于那个访问规则上
    @Bean
    public RouteLocator customerRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes().route(r -> r.path("/pay/**")
                //去掉1个前缀
                .filters(f -> f.stripPrefix(1)
                        .filter(new RequestTimeFilter()))
                .uri("lb://pay-server")
                .order(0)
                .id("test-RequestTimeFilter")
        ).build();
    }
}